import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToMany } from 'typeorm';
import { Role } from './role.entity';

@Entity('sys_permission')
export class Permission {
    @PrimaryGeneratedColumn({ comment: '权限ID' })
    id: number;
    
    @Column({ nullable: true, comment: '父权限ID' })
    parentId: number;

    @Column({ length: 50, unique: true, comment: '权限名称' })
    permName: string;

    @Column({ length: 50, unique: true, comment: '权限标识' })
    permCode: string;
    
    @Column({
        type: 'tinyint',
        default: 1, 
        comment: '权限类型(1-菜单, 2-按钮, 3-接口)' 
    })
    permType: number;

    @Column({ default: 0, comment: '显示顺序' })
    permSort: number;

    @Column({ 
        type: 'tinyint',
        default: 1, 
        comment: '权限状态(1-正常, 0-禁用)' 
    })
    status: number;

    @Column({ length: 500, nullable: true, comment: '备注' })
    remark: string;

    @Column({ length: 50, nullable: true, comment: '创建者' })
    createBy: string;

    @CreateDateColumn({ comment: '创建时间' })
    createTime: Date;

    @Column({ length: 50, nullable: true, comment: '更新者' })
    updateBy: string;

    @UpdateDateColumn({ comment: '更新时间' })
    updateTime: Date;

    @Column({ 
        type: 'tinyint',
        default: 0, 
        comment: '删除标志(0-存在, 1-删除)' 
    })
    delFlag: number;

    @ManyToMany(() => Role, role => role.permissions)
    roles: Role[];
}